<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>登录</title>
<link href="/css/common.css" rel="stylesheet" type="text/css" />
<style>
.content {width:500px;height:400px;margin:50px auto 0;text-align:center;}
.in,.password {width:200px;height:20px;margin:5px 0;}
.password {width:202px;}
.submit {padding:3px 25px;}
.errMsg {color:red;margin:0 0 0 15px;}
</style>
</head>
<body>
<?php include $ROOT_PATH . 'views/include/header.phtml'; ?>
<div class="content">
	<p style="font-size:24px;margin:10px 0;">用户登录</p>
	<table style="width:100%;margin:20px 0 0 0;">
		<tr>
			<td align="right" width="33%">账号：</td>
			<td align="left"><input id="username" type="input" class="in"/><span id="usernameErrMsg" class="errMsg"></span></td>
		</tr>
		<tr>
			<td align="right">密码：</td>
			<td align="left"><input id="password" type="password" class="password"/><span id="passwordErrMsg" class="errMsg"></span></td>
		</tr>
	</table>
	<p style="margin:30px 0 0 0;"><input id="loginBtn" type="button" value="登录" class="submit"/></p>
</div>
<?php include $ROOT_PATH . 'views/include/footer.phtml'; ?>
<script src="js/lib.min.js" type="text/javascript"></script>
<script src="/js/md5.min.js" type="text/javascript"></script>
<script type="text/javascript">
var username = $('#username'),
	usernameErrMsg = $('#usernameErrMsg'),
	password = $('#password'),
	passwordErrMsg = $('#passwordErrMsg'),
	loginBtn = $('#loginBtn');
loginBtn.attr({onclick:function(){
	doLogin();
}});
password.attr({onkeydown:function(e){
	if (e.keyCode==13){
		doLogin();
	}
}});

function doLogin() {
	if (!$.trim(username.val())) {
		usernameErrMsg.html('账号不能为空！');
		username[0].focus();
		return false;
	}
	if (!$.trim(password.val())) {
		usernameErrMsg.html('');
		passwordErrMsg.html('密码不能为空！');
		password[0].focus();
		return false;
	}
	passwordErrMsg.html('');
	loginBtn.disabled = true;
	$.ajax({
		url:"/login.php?op=doLogin", 
		data:{username:$.trim(username.val()), password:hex_md5($.trim(password.val()))}, 
		type:'POST',
		callback:function(res){
			loginBtn.disabled = false;
			if (res.errno == 0){
				location.href = "/admin";
			}else {
				alert(res.errmsg);
			}
		}
	});
}
</script>
</body>
</html>